<?php

namespace app\index\Controller;

use think\Controller;
use app\index\model\Stu as Cla;
use think\Request;
use think\Db;

class Stu extends Controller
{
     
    public function index()
    {

       $stu = new Cla();
       $list = $stu->index();
       //dump($list);
       	 return view("index",["list"=>$list]);
    }

    public function add()//添加
    {
    	$cla = new Cla();
        if(input("?param.sub"))
        {
     
            $file = request() -> file('file');
            if($file)
            {
                //$result = $cla->adds($file);
            }
            else
            {   
                $result = $cla->add();
            }
            if($result)
            {
                $this->success("添加成功","index");
            }
            else
            {
                $this->error("添加失败");
            }
        }
        	else
        	{
            	return view("add");
        	}
    }

    public function delete()//删除
	{
		$id = input("param.id");
		$cla = new Cla();
		//die($id);打印
		$result = $cla->deleteById($id);
		if($result){
			$this->success("删除成功","stu/index");
		}
		else
			{
				$this->error("删除失败");
			}
	}

    public function updat($id)//修改
    {
        $list = Db::table('zf_housing')->select();
        $stu = new Cla();
        if(request()->isPost()){
            $result=$stu->edit($id);
            if($result)
            {
                $this->success("修改成功",'index');
            }
            else
            {
                $this->success("修改失败");
            }
        }
        	else
	        	{
	            $data = Cla::find($id);

	            return view("edit",["data"=>$data,'cate'=>$list]);
	        	}
    }
         public function select()//查询
        {
            // echo input("param.name");die();
            if (input("?param.sub")) {
                $cla = new Cla();
               
                $list = $cla->mh(input('param.name'));
                return view('index', ['list' => $list]);
            }

        }


	    public function delSession()
	    {
	        //Sessjion::delete("username");
	        //清除session(当前作用域)
	        Session::clear();
	    }
	    
	}

